package com.gis507.test.CsvSplit;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class CsvSplitMapper extends Mapper<LongWritable, Text,Text,CsvBean> {

    private Text outK = new Text();
    private CsvBean outV = new CsvBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        // 1获取一行转为String
        String line = value.toString();

        //2 按照逗号分割
        String[] csvComments = line.split(",");

        //3 获取需要的值
        String id = csvComments[0];
        String price = csvComments[2];

        //4 封装到对象
        outV.setId(id);
        outV.setAge(price);

        outK.set(price);

        //5 写出
        context.write(outK,outV);

    }
}
